/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.sf.odinms.net.channel.handler;

import net.sf.odinms.client.MapleClient;
import net.sf.odinms.net.AbstractMaplePacketHandler;
import net.sf.odinms.net.world.guild.MapleAlliance;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Bas
 */
public class AllianceOperationHandler extends AbstractMaplePacketHandler {
    private Logger log = LoggerFactory.getLogger(AllianceOperationHandler.class);
        @Override
        public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
            log.info(slea.toString());

            byte mode = slea.readByte();
            MapleAlliance az = new MapleAlliance(c, c.getChannelServer().getGuildSummary(c.getPlayer().getGuildId()).getAllianceId());

            switch (mode) {
                case 0x01: // show info?
                    //c.getSession().write(MaplePacketCreator.showAllianceInfo(c.getPlayer()));
                    //c.getSession().write(MaplePacketCreator.showAllianceMembers(c.getPlayer()));
                    break;
                case 0x08: // change titles
                    String[] ranks = new String[5];
                    for (int i = 0; i < 5; i++)
                        ranks[i] = slea.readMapleAsciiString();
                    az.setTitles(ranks);
                    c.getPlayer().dropMessage("Done.");
                    break;
                case 0x0A: // change notice
                    String notice = slea.readMapleAsciiString(); // new notice (100 is de max)
                    az.setNotice(notice);
                    break;
                default:
                    log.info("Unknown Alliance operation:\r\n" + slea.toString());
            }
        }
}
